<template>
	<!-- 设置-条款录入-富文本编辑 -->
	<div>
		设置项名称： <a-input style='width: 200px;margin-bottom: 20px;' v-model='name'/>
		<editor-bar ref='editorForm' v-model="detail" :isClear="isClear" @change="change"  ></editor-bar>
		<a-button type='primary' class='mt28' @click='subItemSetting'>提交</a-button>
	</div>
</template>

<script >
	import EditorBar from '@/components/thirdComponent/wangeditor'

	import { EditItemSetting,getSettingItem } from '@/api/minipro/userCenter'

	import bus from '@/utils/bus'
	export default {
		components: { EditorBar },
		name:'settingRichText',
		data() {
	      	return {
		      	isEdit:false,
		        isClear: false,
		        code:'',
		        name:'',
		        detail:""
	        }
		},  
		created(){ 
			if(!!this.$route.query.code){
				this.code = this.$route.query.code
				this.isEdit = true
				this.pageInit()
			}
		},
		methods: {
			pageInit(){
				getSettingItem(this.code).then((res)=>{
					let data = res.data.data
					this.name = data.termsName
					this.detail = data.content
					bus.$emit('initValue',data.content)

				})
			},
		  change(val) {
		      console.log(val)
		      
		    },
		  subItemSetting(){
		  	 
		  	let data = {
		  		code: this.code,
		  		termsName: this.name,
		  		content: this.detail
		  	}
		  	let url = this.isEdit == true ? '/sys/user_terms/modify_user_terms':'sys/user_terms/create_user_terms'
		  	 
		  	EditItemSetting(url,data).then((res)=>{
		  		if(res.data.flag == true){
		  			this.$message.success(res.data.msg);
		  			this.$router.push({path:'/usercentersetting'})
		  		}
		  	})
		  }  
		 }
	}

</script>
